package com.modern.devtools.model;

import javafx.beans.property.*;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * Represents the status of a service being monitored.
 */
public class ServiceStatus {
    
    private final StringProperty serviceId = new SimpleStringProperty();
    private final StringProperty serviceName = new SimpleStringProperty();
    private final StringProperty serverId = new SimpleStringProperty();
    private final StringProperty status = new SimpleStringProperty("UNKNOWN"); // UP, DOWN, UNKNOWN, WARNING
    private final DoubleProperty cpuUsage = new SimpleDoubleProperty(0.0);
    private final DoubleProperty memoryUsage = new SimpleDoubleProperty(0.0);
    private final StringProperty processId = new SimpleStringProperty();
    private final ObjectProperty<LocalDateTime> lastCheck = new SimpleObjectProperty<>();
    private final StringProperty errorMessage = new SimpleStringProperty();
    
    // Constructor
    public ServiceStatus(String serviceId, String serviceName, String serverId) {
        setServiceId(serviceId);
        setServiceName(serviceName);
        setServerId(serverId);
    }
    
    // Getters and Setters
    public String getServiceId() {
        return serviceId.get();
    }
    
    public void setServiceId(String serviceId) {
        this.serviceId.set(serviceId);
    }
    
    public StringProperty serviceIdProperty() {
        return serviceId;
    }
    
    public String getServiceName() {
        return serviceName.get();
    }
    
    public void setServiceName(String serviceName) {
        this.serviceName.set(serviceName);
    }
    
    public StringProperty serviceNameProperty() {
        return serviceName;
    }
    
    public String getServerId() {
        return serverId.get();
    }
    
    public void setServerId(String serverId) {
        this.serverId.set(serverId);
    }
    
    public StringProperty serverIdProperty() {
        return serverId;
    }
    
    public String getStatus() {
        return status.get();
    }
    
    public void setStatus(String status) {
        this.status.set(status);
    }
    
    public StringProperty statusProperty() {
        return status;
    }
    
    public double getCpuUsage() {
        return cpuUsage.get();
    }
    
    public void setCpuUsage(double cpuUsage) {
        this.cpuUsage.set(cpuUsage);
    }
    
    public DoubleProperty cpuUsageProperty() {
        return cpuUsage;
    }
    
    public double getMemoryUsage() {
        return memoryUsage.get();
    }
    
    public void setMemoryUsage(double memoryUsage) {
        this.memoryUsage.set(memoryUsage);
    }
    
    public DoubleProperty memoryUsageProperty() {
        return memoryUsage;
    }
    
    public String getProcessId() {
        return processId.get();
    }
    
    public void setProcessId(String processId) {
        this.processId.set(processId);
    }
    
    public StringProperty processIdProperty() {
        return processId;
    }
    
    public LocalDateTime getLastCheck() {
        return lastCheck.get();
    }
    
    public void setLastCheck(LocalDateTime lastCheck) {
        this.lastCheck.set(lastCheck);
    }
    
    public ObjectProperty<LocalDateTime> lastCheckProperty() {
        return lastCheck;
    }
    
    public String getErrorMessage() {
        return errorMessage.get();
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage.set(errorMessage);
    }
    
    public StringProperty errorMessageProperty() {
        return errorMessage;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ServiceStatus that = (ServiceStatus) o;
        return Objects.equals(serviceId.get(), that.serviceId.get()) &&
               Objects.equals(serverId.get(), that.serverId.get());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(serviceId.get(), serverId.get());
    }
    
    @Override
    public String toString() {
        return "ServiceStatus{" +
                "serviceId='" + serviceId.get() + '\'' +
                ", serviceName='" + serviceName.get() + '\'' +
                ", serverId='" + serverId.get() + '\'' +
                ", status='" + status.get() + '\'' +
                ", cpuUsage=" + cpuUsage.get() +
                ", memoryUsage=" + memoryUsage.get() +
                '}';
    }
}
